package org.example.chapter3;

import java.util.Scanner;
//使用用户确认或标记值控制循环
public class AddquizLoop {
    public static void main(String[] args) {
        char continueLoop='Y';
        Scanner in = new Scanner(System.in);
        int count=0;
        int correctCount=0;
        String output="";
        long starttime=System.currentTimeMillis();
        while(continueLoop=='Y'){
            int number1=(int)(Math.random()*10);
            int number2=(int)(Math.random()*10);

            System.out.println(
                    "What is " + number1 + " + " + number2 + "?"
            );

            int answer=in.nextInt();
            count++;
            if(answer==number1+number2){
                correctCount++;
                System.out.println("You are correct");
            }else{
                System.out.println("You answer is incorrect "+ number1 + " + " + number2+" should be "+(number1+number2));
            }
            output+="\n"+number1+" + "+number2+" = "+answer+(((number1+number2)==answer)?"\tcorrect":"\tincorrect");
            System.out.println("Enter Y to continue and N to exit");
            continueLoop=in.next().charAt(0);

        }
        long endtime=System.currentTimeMillis();
        long testtime=endtime-starttime;
        System.out.println("------------------------");
        System.out.println("Total count is "+count+"\tCorrect count is "+correctCount+"\nTest time is "+testtime/1000+"seconds\n"+output);
    }
}
